/*
 * Created on Jan 12, 2011 by Eng. Julian Rousselot
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package ar.com.visualAORE.model;

import ar.com.visualAORE.exceptions.NoHighlightTagException;


/**
 * @author julian
 *
 */
public class Selection implements Comparable<Selection>{
	int highlightTagNumber;
	private int dot;
	private int mark;
	private Concern concern;
	private int size;
	private int lineNumber;
	
	public Selection(int dot, int mark, Concern concern, int size, int lineNumber, int highlightTagNumber){
		this.dot = dot;
		this.mark = mark;
		this.concern = concern;
		this.size = size;
		this.lineNumber = lineNumber;
		this.highlightTagNumber = highlightTagNumber;
	}

	public int getDot() {
		return dot;
	}

	public void setDot(int dot) {
		this.dot = dot;
	}

	public int getMark() {
		return mark;
	}

	public void setMark(int mark) {
		this.mark = mark;
	}

	public Concern getConcern() {
		return concern;
	}

	public void setConcern(Concern concern) {
		this.concern = concern;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public int getLineNumber() {
		return lineNumber;
	}

	public void setLineNumber(int lineNumber) {
		this.lineNumber = lineNumber;
	}
	
	public int getHighlightTagNumber() {
		return highlightTagNumber;
	}

	public void setHighlightTag(int highlightTagNumber) {
		this.highlightTagNumber = highlightTagNumber;
	}

	@Override
	public String toString() {
		return "Selection [concern=" + concern + ", dot=" + dot + ", mark="
				+ mark + ", size=" + size + "]";
	}
	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Selection o) {
		 if(this.getDot() > o.getDot())
	            return 1;
	        else if(this.getDot() < o.getDot())
	            return -1;
	        else
	            return 0;
	}
	
	public Object getSelectionTag(int position){
		if((position >= dot) && (position <= mark))
			return highlightTagNumber;
		else
			return new NoHighlightTagException();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + highlightTagNumber;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Selection other = (Selection) obj;
		if (highlightTagNumber != other.highlightTagNumber)
			return false;
		return true;
	}

	
	
}